package test;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Vector;

import wfta.common.Order;
import wfta.common.Section;

public class Client extends Thread{

	int ID;
	Client(int id){
		ID=id;
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		for(int i=0;i<5;i++){
			new Client(i).start();
			System.out.println("\t\tNew Client");
		}
	}

	public void run() {
		try {
			Socket s=new Socket("localhost", 4444);

			ObjectOutputStream o=new ObjectOutputStream(s.getOutputStream());
			ObjectInputStream i=new ObjectInputStream(s.getInputStream());

			Vector<Section> menu=(Vector<Section>)i.readObject();

			Order o1=new Order(8, 20);
			Order o2=new Order(8, 1);
			Vector<Order> vo=new Vector<Order>();

			vo.add(o1);

			o.writeObject(vo);

			String msg=(String)i.readObject();
			System.out.println(ID+" "+msg);
			
			Vector<Order> vo2=new Vector<Order>();
			vo2.add(o2);
			o.writeObject(vo2);
			

			String msg5=(String)i.readObject();
			System.out.println(ID+" "+msg5);
			
			String msg2=(String)i.readObject();
			System.out.println(ID+" "+msg2);
			String msg3=(String)i.readObject();
			System.out.println(ID+" "+msg3);

			s.close();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
